package br.ucdb.acad.util;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import br.ucdb.acad.domain.GpsPosition;
import br.ucdb.android.maps.R;


public class GpsUtil extends Activity implements LocationListener {

	private Location location;
	private Boolean ligado;
	
	public GpsUtil() {
		LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
		locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
		locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
		//location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		
		boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER); 
	}

	public Location getLocation() {
		return location;
	}
	
	public void isActivedGps(final Context resolver){
		
		final Dialog dialog=new Dialog(resolver);
		dialog.setContentView(R.layout.gps);
		dialog.setTitle("GPS");
		dialog.setCancelable(false);

		Button gpsSettings = (Button) dialog.findViewById(R.id.gps_sett_button);
		gpsSettings.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
				resolver.startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); 
			}
		});

		Button gpsCancel = (Button) dialog.findViewById(R.id.gps_cancel_button);
		gpsCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}
		});
		dialog.show();
		
		
	}
	
	public static GpsPosition getPosition(){
		return null;
	}

	@Override
	public void onLocationChanged(Location location) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}

	
}
